//
//  MyRulesViewController.m
//  smarthings
//
//  Created by Stefan Tsvyatkov on 10/28/14.
//  Copyright (c) 2014 Stefan Tsvyatkov. All rights reserved.
//

#import "MyRulesViewController.h"
#import <MBProgressHUD.h>

@interface MyRulesViewController ()

- (void)refresh;

@end

@implementation MyRulesViewController

- (void)viewWillAppear:(BOOL)animated {
    [self refresh];
}

- (IBAction)refreshButtonTapped:(id)sender {
    [self refresh];
}

- (void)timerAction:(NSTimer *)timer {
    [MBProgressHUD hideAllHUDsForView:self.tabBarController.view animated:YES];
    [timer invalidate];
}

- (void)refresh {
    [MBProgressHUD showHUDAddedTo:self.tabBarController.view animated:YES];
    [NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self
                                   selector:@selector(timerAction:)
                                   userInfo:nil
                                    repeats:NO];
}

#pragma mark - Table view data source

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Unsupported rule" message:@"The selected rule is a complex rule that is not supported by the mobile app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        alert.tag = 0;
        [alert show];
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
}

@end
